home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / X11 / tclMotif-1.4 / doc / examples / UserForm.tcl < prev    next >
Encoding:
Text File  |  1995-06-29  |  2.8 KB  |  86 lines

  1. #! moat
  2.  
  3. xtAppInitialize
  4.  
  5. proc MakeUserForm {{root ""}} {
  6.     set f [xmForm $root.form managed]
  7.     $f setValues -marginHeight 5 -marginWidth 5
  8.  
  9.     xmLabel $f.userl managed -labelString "login name:" -x 5 -y 5
  10.     xmTextField $f.user managed -value "" -y 5 -width 150 \
  11.         -leftAttachment attach_widget -leftWidget $f.userl
  12.  
  13.     xmLabel $f.uidl managed -labelString "uid:" \
  14.         -x 5 -topOffset 5 -topAttachment attach_widget -topWidget $f.userl
  15.     xmTextField $f.uid managed -value "100" -width 100 \
  16.         -topAttachment attach_opposite_widget -topWidget $f.uidl \
  17.         -leftAttachment attach_widget -leftWidget $f.uidl
  18.  
  19.     xmLabel $f.gidl managed -labelString "gid:" \
  20.         -topOffset 5 -x 5 -topAttachment attach_widget -topWidget $f.uid
  21.     xmTextField $f.gid managed -value "100" -width 100 \
  22.         -leftAttachment attach_widget -leftWidget $f.gidl \
  23.         -topAttachment attach_opposite_widget -topWidget  $f.gidl
  24.  
  25.     xmLabel $f.gcosl managed -labelString "finger field:" \
  26.         -topOffset 5 -x 5 -topAttachment attach_widget -topWidget $f.gid
  27.     xmTextField $f.gcos managed -value ",,," -width 150 \
  28.         -leftAttachment attach_widget -leftWidget $f.gcosl \
  29.         -topAttachment attach_opposite_widget -topWidget $f.gcosl \
  30.         -rightAttachment attach_form
  31.     
  32.     xmLabel $f.homel managed -labelString "home directory:" \
  33.         -topOffset 5 -x 5 -topAttachment attach_widget -topWidget $f.gcos
  34.     xmTextField $f.home managed -value "/users" -width 150 \
  35.         -leftAttachment attach_widget -leftWidget $f.homel \
  36.         -topAttachment attach_opposite_widget -topWidget $f.homel \
  37.         -rightAttachment attach_form
  38.     
  39.     xmLabel $f.shelll managed -labelString "shell:" \
  40.         -topOffset 5 -x 5 -topAttachment attach_widget -topWidget $f.home
  41.     xmTextField $f.shell managed -value "/bin/sh" -width 80 \
  42.         -leftAttachment attach_widget -leftWidget $f.shelll \
  43.         -topAttachment attach_opposite_widget -topWidget $f.shelll \
  44.         -rightAttachment attach_form \
  45.         -bottomOffset 5 -bottomAttachment attach_form
  46.     
  47.     foreach w {user uid gid gcos home shell} {
  48.          $f.$w modifyVerifyCallback "CheckUserField $f $w"
  49.     }
  50.  
  51.     return $f
  52. }
  53.  
  54. proc FieldCirculate {form widget wlist} {
  55.     set i [expr ([lsearch $wlist $widget]+1)%[llength $wlist]]
  56.     set widget [lindex $wlist $i]
  57.     SetInputFocus $form.$widget
  58. }
  59.  
  60. proc CheckUserField {form field} {
  61.     switch $field {
  62.         uid
  63.             -
  64.         gid {
  65.             set id [expr 0+[$form.$field getString]]
  66.             # $form.$field setValues -value $id
  67.         }
  68.     }
  69. }
  70.  
  71. proc SetUserData {f pwdline} {
  72.     set fields [split $pwdline ":"]
  73.     
  74.     $f.user setValues -value [lindex $fields 0]
  75.     $f.uid  setValues -value [lindex $fields 2]
  76.     $f.gid  setValues -value [lindex $fields 3]
  77.     $f.gcos setValues -value [lindex $fields 4]
  78.     $f.home setValues -value [lindex $fields 5]
  79.     $f.shell  setValues -value [lindex $fields 6]
  80. }
  81.  
  82. SetUserData [MakeUserForm] "js:*:100:101:John Smith,4858,321-4312,:/users/js:/bin/sh"
  83.  
  84. . realizeWidget
  85. . mainLoop
  86.